$(document).ready(function() {
    /*
     * FancyBox Effect
     */
    // iPhone App
    $("a#ipapp").click(function() {
        $.fancybox([
			{
			'href' : './img/1_b_1.jpg',
			'title' : 'SleepDetective detects noise decibel from microphone and determines whether the environment is ok for sleep.'
			},
			{
			'href' : './img/1_b_2.jpg',
			'title' : 'Accelerometer sensor could detect phone shake caused by body movement,and App records and visualizes sleep data.'
			}
        	], {
            'overlayColor' : '#333',
            'overlayOpacity':'0.3',
            'padding' : 0,
            'titlePosition' : 'over',
            'transitionIn' : 'fade',
            'transitionOut' : 'fade',
            'type' : 'image',
            'changeFade' : 300
        });
    });

    // Personal Web
    $("a#feiweb").fancybox({
		'title' : 'My Personal Website.Featured on cssmania.com and onepagelove.com',
		'titlePosition' : 'over'
		}
	);

    // Twitter Map
    $("a#twtmap").fancybox(
		{
			'title' : 'Twitter Map',
			'titlePosition' : 'over'
		}
	);

    // Autosys
    $("a#autosys").click(function() {
        $.fancybox(['./img/4_b_1.jpg','./img/4_b_2.jpg','./img/4_b_3.jpg','./img/4_b_4.jpg'], {
            'overlayColor' : '#333',
            'overlayOpacity':'0.3',
            'padding' : 0,
            'titlePosition' : 'over',
            'transitionIn' : 'fade',
            'transitionOut' : 'fade',
            'type' : 'image',
            'changeFade' : 300
        });
    });

    // Remote Task Mananager
    $("a#taskmgr").click(function() {
        $.fancybox(['./img/5_b_1.jpg','./img/5_b_2.jpg','./img/5_b_3.jpg','./img/5_b_4.jpg'], {
            'overlayColor' : '#333',
            'overlayOpacity':'0.3',
            'padding' : 0,
            'titlePosition' : 'over',
            'transitionIn' : 'fade',
            'transitionOut' : 'fade',
            'type' : 'image',
            'changeFade' : 300
        });
    });

    // Opengl
    $("#3dworld").fancybox({
        'autoScale' : false,
        'transitionIn' : 'none',
        'transitionOut' : 'none',
        'type' : 'iframe'
    });// end

    // flickr gallery
    $('#flickrgallery').click(function(){
        $.ajax({
            url: 'flickrgallery.php',
            dataType:"json",
            success: fancyboxResponse,
            error: function(){
                alert('Error during AJAX call. Please try again');
            }
        });
    });
    function fancyboxResponse(json){
        $.fancybox(json,{
            'titlePosition': 'over',
            'titleFormat': function(title, currentArray, currentIndex, currentOpts) {
                return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
            }
        });
    }// end
        
    /*
	 * Show Project Description when Hovering
	 */
    $('#work-showcase > .icon-container').hover(
        function(){
            $('.showcase-desc ul').remove();
            $('.showcase-desc').append($(this).children("span").children("ul").clone());
            $('.showcase-desc ul').hide()
                                  .fadeIn('fast');
//            $(this).children("span").children("ul").clone().appendTo(".showcase-desc");
            $('.showcase-desc').fadeIn('slow');
        // $('.showcase-desc > p').html($(this).children("span").text());
        // $('.showcase-desc > p').append($(this).children("span").removeClass("hide"));
        },
        function(){
            // $('.showcase-desc').html("");
//            $('.showcase-desc ul').remove();
        })// end
}); 